package view;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

import util.Comandos;
import controller.CorporalController;
import java.awt.Font;

public class CorporalFrame extends JDialog {

	private static final long serialVersionUID = 1L;
	private JLabel jLabel0;
	private JLabel jLabel1;
	private JLabel jLabel2;
	private JLabel jLabel3;
	private JLabel jLabel4;
	private JLabel jLabel5;
	private JLabel jLabel6;
	private JLabel jLabel7;
	private JLabel jLabel8;
	private JPanel jPanel1;
	
	private JTextField muniecaText;
	private JTextField alturaText;
	private JTextField pesoText;
		
	private JRadioButton hombreRadio;
	private JRadioButton mujerRadio;
	private JButton calcularButton;
	
	private JLabel porcentajeGraso;
	private JLabel masaAdiposa;
	private JLabel masaMagra;
	
	private ButtonGroup sexoGroup;
	private JLabel jLabel96;
	private JTextField edadText;
	private JLabel jTipoPersona;
	private JLabel lblAos;
	private JButton btnCap;

	public CorporalFrame(PrincipalFrame principal) {
		setResizable(false);
		initComponents();
	}

	private void initComponents() {
		setTitle("Composición Corporal");
		getContentPane().setLayout(null);
		getContentPane().add(getJButton0());
		getContentPane().add(getJLabel0());
		getContentPane().add(getJLabel1());
		getContentPane().add(getJLabel2());
		getContentPane().add(getJLabel96());
		getContentPane().add(getJTextField0());
		getContentPane().add(getJTextField1());
		getContentPane().add(getJTextField2());
		getContentPane().add(getJTextField3());
		getContentPane().add(getJLabel3());
		getContentPane().add(getJLabel4());
		getContentPane().add(getJLabel5());
		getContentPane().add(getLblAos());
		getContentPane().add(getJLabel6());
		getContentPane().add(getJLabel7());
		getContentPane().add(getJLabel8());
		getContentPane().add(getJLabel97());
		getContentPane().add(getJLabel9());
		getContentPane().add(getJLabel10());
		getContentPane().add(getJLabel11());
		getContentPane().add(getJPanel1());
		getContentPane().add(getBtnCap());
		initSexoGroup();
		setSize(970, 292);
	}

	private JLabel getJLabel97() {
		if (jTipoPersona == null) {
			jTipoPersona = new JLabel();
			jTipoPersona.setBounds(514, 180, 388, 28);
			jTipoPersona.setFont(new Font("Dialog", Font.PLAIN, 21));
		}
		return jTipoPersona;
	}

	private void initSexoGroup() {
		sexoGroup = new ButtonGroup();
		sexoGroup.add(getJRadioButton0());
		sexoGroup.add(getJRadioButton1());
	}

	private JTextField getJTextField3() {
		if (edadText == null) {
			edadText = new JTextField();
			edadText.setBounds(154, 181, 62, 25);
			edadText.setFont(new Font("Dialog", Font.PLAIN, 21));
		}
		return edadText;
	}

	private JLabel getJLabel96() {
		if (jLabel96 == null) {
			jLabel96 = new JLabel();
			jLabel96.setBounds(64, 180, 54, 28);
			jLabel96.setFont(new Font("Dialog", Font.PLAIN, 21));
			jLabel96.setText("Edad:");
		}
		return jLabel96;
	}

	private JPanel getJPanel1() {
		if (jPanel1 == null) {
			jPanel1 = new JPanel();
			jPanel1.setBounds(334, 63, 123, 97);
			jPanel1.setLayout(null);
			jPanel1.add(getJRadioButton0());
			jPanel1.add(getJRadioButton1());
			
			sexoGroup = new ButtonGroup();
			sexoGroup.add(hombreRadio);
			sexoGroup.add(mujerRadio);
		}
		return jPanel1;
	}

	private JLabel getJLabel11() {
		if (masaMagra == null) {
			masaMagra = new JLabel();
			masaMagra.setBounds(802, 112, 79, 28);
			masaMagra.setFont(new Font("Dialog", Font.PLAIN, 21));
		}
		return masaMagra;
	}

	private JLabel getJLabel10() {
		if (masaAdiposa == null) {
			masaAdiposa = new JLabel();
			masaAdiposa.setBounds(802, 73, 79, 28);
			masaAdiposa.setFont(new Font("Dialog", Font.PLAIN, 21));
		}
		return masaAdiposa;
	}

	private JLabel getJLabel9() {
		if (porcentajeGraso == null) {
			porcentajeGraso = new JLabel();
			porcentajeGraso.setBounds(800, 63, 67, 28);
			porcentajeGraso.setFont(new Font("Dialog", Font.PLAIN, 21));
		}
		return porcentajeGraso;
	}

	private JLabel getJLabel8() {
		if (jLabel8 == null) {
			jLabel8 = new JLabel();
			jLabel8.setBounds(514, 141, 123, 28);
			jLabel8.setFont(new Font("Dialog", Font.PLAIN, 21));
			jLabel8.setText("Masa Magra:");
		}
		return jLabel8;
	}

	private JLabel getJLabel7() {
		if (jLabel7 == null) {
			jLabel7 = new JLabel();
			jLabel7.setBounds(514, 102, 139, 28);
			jLabel7.setFont(new Font("Dialog", Font.PLAIN, 21));
			jLabel7.setText("Masa Adiposa:");
		}
		return jLabel7;
	}

	private JLabel getJLabel6() {
		if (jLabel6 == null) {
			jLabel6 = new JLabel();
			jLabel6.setBounds(514, 63, 264, 28);
			jLabel6.setFont(new Font("Dialog", Font.PLAIN, 21));
			jLabel6.setText("Porcentaje Graso Estimado:");
		}
		return jLabel6;
	}

	private JRadioButton getJRadioButton1() {
		if (mujerRadio == null) {
			mujerRadio = new JRadioButton();
			mujerRadio.setFont(new Font("Tahoma", Font.PLAIN, 19));
			mujerRadio.setBounds(17, 56, 83, 23);
			mujerRadio.setText("Mujer");
		}
		return mujerRadio;
	}

	private JButton getJButton0() {
		if (calcularButton == null) {
			calcularButton = new JButton();
			calcularButton.setBounds(334, 171, 123, 37);
			calcularButton.setFont(new Font("Dialog", Font.PLAIN, 21));
			calcularButton.setText("Calcular");
		}
		return calcularButton;
	}

	private JRadioButton getJRadioButton0() {
		if (hombreRadio == null) {
			hombreRadio = new JRadioButton();
			hombreRadio.setFont(new Font("Tahoma", Font.PLAIN, 19));
			hombreRadio.setBounds(17, 18, 99, 23);
			hombreRadio.setSelected(true);
			hombreRadio.setText("Hombre");
		}
		return hombreRadio;
	}

	private JLabel getJLabel5() {
		if (jLabel5 == null) {
			jLabel5 = new JLabel();
			jLabel5.setBounds(226, 141, 31, 28);
			jLabel5.setFont(new Font("Dialog", Font.PLAIN, 21));
			jLabel5.setText("Kg.");
		}
		return jLabel5;
	}

	private JLabel getJLabel4() {
		if (jLabel4 == null) {
			jLabel4 = new JLabel();
			jLabel4.setBounds(226, 102, 37, 28);
			jLabel4.setFont(new Font("Dialog", Font.PLAIN, 21));
			jLabel4.setText("Cm.");
		}
		return jLabel4;
	}

	private JLabel getJLabel3() {
		if (jLabel3 == null) {
			jLabel3 = new JLabel();
			jLabel3.setBounds(226, 63, 37, 28);
			jLabel3.setFont(new Font("Dialog", Font.PLAIN, 21));
			jLabel3.setText("Cm.");
		}
		return jLabel3;
	}

	private JTextField getJTextField2() {
		if (pesoText == null) {
			pesoText = new JTextField();
			pesoText.setBounds(154, 142, 62, 25);
			pesoText.setFont(new Font("Dialog", Font.PLAIN, 21));
		}
		return pesoText;
	}

	private JTextField getJTextField1() {
		if (alturaText == null) {
			alturaText = new JTextField();
			alturaText.setBounds(154, 103, 62, 25);
			alturaText.setFont(new Font("Dialog", Font.PLAIN, 21));
		}
		return alturaText;
	}

	private JTextField getJTextField0() {
		if (muniecaText == null) {
			muniecaText = new JTextField();
			muniecaText.setBounds(154, 64, 62, 25);
			muniecaText.setFont(new Font("Dialog", Font.PLAIN, 21));
		}
		return muniecaText;
	}

	private JLabel getJLabel2() {
		if (jLabel2 == null) {
			jLabel2 = new JLabel();
			jLabel2.setBounds(64, 141, 55, 28);
			jLabel2.setFont(new Font("Dialog", Font.PLAIN, 21));
			jLabel2.setText("Peso:");
		}
		return jLabel2;
	}

	private JLabel getJLabel1() {
		if (jLabel1 == null) {
			jLabel1 = new JLabel();
			jLabel1.setBounds(64, 102, 59, 28);
			jLabel1.setFont(new Font("Dialog", Font.PLAIN, 21));
			jLabel1.setText("Altura:");
		}
		return jLabel1;
	}

	private JLabel getJLabel0() {
		if (jLabel0 == null) {
			jLabel0 = new JLabel();
			jLabel0.setBounds(64, 63, 80, 28);
			jLabel0.setFont(new Font("Dialog", Font.PLAIN, 21));
			jLabel0.setText("Muñeca:");
		}
		return jLabel0;
	}

	public void setActionListeners(final CorporalController corporalController)
	{
		calcularButton.setActionCommand(Comandos.CALCULAR_CORPORAL.toString());
		calcularButton.addActionListener(corporalController);
		
		btnCap.setActionCommand(Comandos.CAPTURA.toString());
		btnCap.addActionListener(corporalController);
	}

	public String getMunieca()
	{
		return muniecaText.getText();
	}
	
	public String getPeso()
	{
		return pesoText.getText();
	}

	public String getAltura()
	{
		return alturaText.getText();
	}
	
	public String getEdad()
	{
		return edadText.getText();
	}
	
	public void setPorcetajeGraso(String graso)
	{
		porcentajeGraso.setText(graso);
	}
	
	public void setMasaAdiposa(String adiposa)
	{
		masaAdiposa.setText(adiposa);
	}
	
	public void setMasaMagra(String magra)
	{
		masaMagra.setText(magra);
	}
	
	public String getSexo()
	{
		String sexo;
		if(hombreRadio.isSelected()){
			sexo = "hombre";
		}
		else{
			sexo = "mujer";
		}
		return sexo;
	}

	public void setTipoPersona(String tipoPersona) {
		jTipoPersona.setText(tipoPersona);
	}
	private JLabel getLblAos() {
		if (lblAos == null) {
			lblAos = new JLabel();
			lblAos.setText("Años");
			lblAos.setFont(new Font("Dialog", Font.PLAIN, 21));
			lblAos.setBounds(226, 180, 59, 28);
		}
		return lblAos;
	}
	private JButton getBtnCap() {
		if (btnCap == null) {
			btnCap = new JButton("CAP");
			btnCap.setFont(new Font("Tahoma", Font.PLAIN, 16));
			btnCap.setBounds(876, 11, 78, 23);
		}
		return btnCap;
	}
}
